package com.rongc.client.freight.business.supply.view.activity;

import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;

import com.rongc.client.core.exception.RegexException;
import com.rongc.client.core.utils.ActivityUtils;
import com.rongc.client.core.utils.RegexUtil;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.BaseActivity;

import butterknife.Bind;

/**
 * Created by ccqx on 2017/7/1.
 */

public class SupplyCreateMessageActivity extends BaseActivity {
    @Bind(R.id.et_content)
    EditText mEtContent;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.map_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_define:
                try{


                    prepare();

                    Intent intent = new Intent();
                    intent.putExtra("data",mEtContent.getText().toString());
                    setResult(RESULT_OK,intent);
                    finish();
                }catch (RegexException e){
                    ActivityUtils.toast(e.getMessage());
                }


                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    void prepare() throws RegexException {
        if(!RegexUtil.checkNotNull(mEtContent.getText().toString())){
            throw new RegexException("请输入留言");
        }
    }

    @Override
    public void initView() {
        initToolbar(R.string.supply_leave_title);

    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_create_message;
    }
}
